package com.xy.framework.base.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.math.NumberUtils;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xy.framework.base.User;
import com.xy.framework.pager.PageRequest;

public class BaseController {

	static Logger log = LoggerFactory.getLogger(BaseController.class);

	protected User getCurrentMember() {
		return (User) SecurityUtils.getSubject().getSession().getAttribute("user");
	}

	protected PageRequest newPageRequest(HttpServletRequest request) {
		int pageIndex = NumberUtils.toInt(request.getParameter("pageIndex"), 1);
		int pageSize = NumberUtils.toInt(request.getParameter("pageSize"),10);

		String sortCol = request.getParameter("sortCol");
		String sortOrder = request.getParameter("sortOrder");
		return new PageRequest(pageIndex, pageSize, sortCol, sortOrder);
	}
}
